home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 207_01 / checks.c < prev    next >
Text File  |  1980-01-01  |  29KB  |  766 lines

  1. /*  checks.c -- main source file for check register program                  */
  2.  
  3. /*  copyright (c) 1986 by Jim Woolley and WoolleyWare, San Jose, CA          */
  4.  
  5. /*  vers. 1.0, 12/85 thru 5/86
  6.  */
  7.  
  8. /*  this file contains:
  9.  *      main()
  10.  *      startup()
  11.  *      getval( q)
  12.  *      getentry()
  13.  *      getinfo()
  14.  *      getyesno( def)
  15.  *      struct nlist *install( name, def)
  16.  *      struct nlist *lookup( s)
  17.  *      hash( s)
  18.  *      char *strsave( s)
  19.  *      compdate( e1, e2)
  20.  *      datecomp( d1, d2)
  21.  *      comppayee( e1, e2)
  22.  *      compcateg( e1, e2)
  23.  *      categcomp( e1, e2)
  24.  *      compamount( e1, e2)
  25.  *      compbbf( e1, e2)
  26.  *      compabrev( p1, p2)
  27.  *      isebbf( e)
  28.  *      isibbf( i)
  29.  *      char *index( s, c)
  30.  *      char *skipspace( s)
  31.  *      typcat( f, t)
  32.  *      openerr()
  33.  *      readerr()
  34.  *      writerr( s)
  35.  *      createrr( s)
  36.  *      baddisk()
  37.  */
  38.  
  39. #include    "a:checks.h"
  40.  
  41. main( argc, argv)                       /*  check register program           */
  42. int argc;
  43. char *argv[];
  44. {
  45.     char *p, *copyright, *allrights;
  46.     int i, length;
  47.  
  48.     copyright = "Check Register Program, v.1.0 (c) 1986 by WoolleyWare";
  49.                 /*  copyright must be < (COLS - FNAMSIZE - 3) chars          */
  50.     allrights = "All Rights Reserved";
  51.  
  52.     _Outdev = CONOUT;                   /*  direct putchar() to screen       */
  53.     _Lastch = 0;                        /*  used by getchar()/ungetch()      */
  54.     Speed = 5;                          /*  initial Speed for ^QW and ^QZ    */
  55.     Today.yy = 0;                       /*  initialize other globals         */
  56.     Savrecno = Oldfield = -1;
  57.     Modified = Printing = Ctrlyundo = FALSE;
  58.     for ( i = 0; i < HASHSIZE; ++i)
  59.         Hashtab[ i] = 0;
  60.     strcpy( Title, copyright);
  61.     Ftoc[ MMFIELD] = 1;                 /*  Ftoc[ f] = c                     */
  62.     Ftoc[ DDFIELD] = 4;                 /*  locates cursor for Field f       */
  63.     Ftoc[ YYFIELD] = 7;                 /*  at column c, where c = 0         */
  64.     Ftoc[ PAYFIELD] = 9;                /*  corresponds to left edge         */
  65.     Ftoc[ CATFIELD] = 52;               /*  of screen                        */
  66.     Ftoc[ AMTFIELD] = 61;
  67.     Ftoc[ DEPFIELD] = 63;
  68.     Ftoc[ CLRFIELD] = 67;
  69.  
  70.     if ( argc > 1)                      /*  get Filename root                */
  71.         p = argv[ 1];
  72.     else p = DEFNAM;
  73.     length = strlen( p);
  74.     if ( !index( p, ':'))               /*  if no drive designated           */
  75.     {
  76.         Filename[ 0] = 'A' + defdsk();
  77.         Filename[ 1] = ':';
  78.         i = 2;
  79.     }
  80.     else                                /*  drive was designated             */
  81.     {
  82.         if ( length == 2)               /*  if just d: without filename      */
  83.         {
  84.             strcpy( Filename, p);
  85.             p = DEFNAM;                 /*  use default                      */
  86.             i = 2;
  87.         }
  88.         else i = 0;
  89.     }
  90.     if ( length > ( FNAMSIZE - 5 - i))  /*  should be FALSE if p = DEFNAM    */
  91.         *( p + FNAMSIZE - 5 - i) = '\0';
  92.     strcpy(( Filename + i), p);
  93.     if ( !( p = index( Filename, '.'))) /*  add dot if none                  */
  94.         *( p = Filename + strlen( Filename)) = '.';
  95.     *( p + 1) = '\0';                   /*  truncate after dot               */
  96.  
  97.     startup();
  98.     getentry();                         /*  read entry data                  */
  99.     disheading();                       /*  initialize display               */
  100.     Recno = Maxentry + ( 1 - PAGE);     /*  initialize gobottom()            */
  101.     First = Recno - PAGE;
  102.     Last = First - 1;
  103.     Field = 0;
  104.     gobottom();
  105.     getinfo();                          /*  read title, abrev, auto entries  */
  106.     control();                          /*  never returns                    */
  107. }
  108.  
  109. startup()                               /*  startup check register program   */
  110. {
  111.     char line, *p, *q, s[ MAXLINE], f[ FNAMSIZE], buf[ BUFSIZ], *fgets();
  112.     int i;
  113.  
  114.     strcpy( f, DEFNAM);
  115.     typcat( f, SCRTYP);
  116.     if ( fopen( f, buf) == ERROR)
  117.         abort( "Cannot open ", f);      /*  never returns                    */
  118.     for ( line = 6; line; --line)       /*  skip 6 lines                     */
  119.         if ( !fgets( s, buf))
  120.             readerr( f);                /*  never returns                    */
  121.     for ( line = 0; line < 11; ++line)  /*  get cursor/screen controls       */
  122.     {
  123.         if ( !fgets(( q = s), buf))
  124.             readerr( f);                /*  never returns                    */
  125.         switch ( line)
  126.         {
  127.         case 0:
  128.             p = Clead1;
  129.             break;
  130.         case 1:
  131.             p = Clead2;
  132.             break;
  133.         case 2:
  134.             p = Ctrail;
  135.             break;
  136.         case 3:
  137.             Cb4flg = getval( &q);
  138.             Linoff = getval( &q);
  139.             Coloff = getval( &q);
  140.             if ( Ascur = getval( &q))   /*  Ascur must be 0, 2, or 3         */
  141.                 Ascur = min( 3, max( 2, Ascur));
  142.             break;
  143.         case 4:
  144.             p = Eraeol;
  145.             break;
  146.         case 5:
  147.             p = Lindel;
  148.             break;
  149.         case 6:
  150.             p = Linins;
  151.             break;
  152.         case 7:
  153.             p = Ivon;
  154.             break;
  155.         case 8:
  156.             p = Ivoff;
  157.             break;
  158.         case 9:
  159.             p = Trmini;
  160.             break;
  161.         case 10:
  162.             Dloop = (( DLOOP/10)*max( 1, min( 1000, getval( &q))))/10;
  163.             Inserton = getval( &q);
  164.             break;
  165.         default:
  166.             break;
  167.         }
  168.         if ( line != 3)                 /*  note that i may be negative      */
  169.             for ( *p++ = i = getval( &q); i > 0; --i)
  170.                 *p++ = getval( &q);
  171.     }
  172.     if ( fgets( s, buf))                /*  if more than 17 lines            */
  173.     {
  174.         clrscr();
  175.         while (( i = getc( buf)) != CPMEOF && i != ERROR)
  176.             putchar( i - 1);
  177.         if ( getchar() == CTRLC)
  178.             exit();                     /*  never returns                    */
  179.     }
  180.     fclose( buf);
  181.     clrscr();
  182. }
  183.  
  184. /*  getval( q) returns next int value from string of decimal numbers separated
  185.  *  by white space; string must be pointed to by *q; each decimal number in
  186.  *  string may be headed by white space with optional minus sign followed by
  187.  *  consecutive decimal digits; first non-digit terminates the scan; zero is
  188.  *  returned if no legal value is found; *q will be updated to point to first
  189.  *  white space char following the current decimal number; *q will not point
  190.  *  beyond end of string
  191.  *
  192.  *  sample calling program segment:
  193.  *
  194.  *      char *p;                        string pointer
  195.  *      p = " 1   -32 123   9";         point to typical space separated string
  196.  *      printf( "%d", getval( &p));     pass pointer to string pointer
  197.  */
  198.  
  199. getval( q)                              /*  return int value and update *q   */
  200. char **q;                               /*  pointer to string pointer        */
  201. {
  202.     int i;
  203.  
  204.     i = atoi( *q = skipspace( *q));
  205.     while ( !isspace( **q) && **q)
  206.         ++( *q);
  207.     return ( i);
  208. }
  209.  
  210. getentry()                              /*  get check register entries       */
  211. {
  212.     char *p, buf[ BUFSIZ];
  213.     int g, imax;
  214.  
  215.     typcat( Filename, DATTYP);
  216.     if ( fopen( Filename, buf) == ERROR)
  217.     {
  218.         openerr( Filename);
  219.         Maxentry = -1;                  /*  initialize                       */
  220.         Memory.dollar = Memory.cent = 0;
  221.         return;
  222.     }
  223.     if (( g = getw( buf)) == ERROR)
  224.         readerr( Filename);             /*  never returns                    */
  225.     imax = RECSIZ*g;
  226.     Maxentry = g - 1;
  227.     Memory.dollar = getw( buf);         /*  assume no read error             */
  228.     Memory.cent = getw( buf);
  229.     p = Entry;
  230.     while ( imax--)
  231.     {
  232.         if (( g = getc( buf)) == ERROR)
  233.             readerr( Filename);         /*  never returns                    */
  234.         *p++ = g;
  235.     }
  236.     fclose( buf);
  237.     for ( g = 0; g <= Maxentry; ++g)
  238.         newbalance( g);
  239. }
  240.